namespace SinaFinance.ChartLibrary.AxisLibrary
{
    using System;
    using System.Diagnostics;
    using System.Runtime.CompilerServices;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Input;
    using System.Windows.Media;

    public partial class ComparationItem : UserControl
    {
        //private bool _contentLoaded;
        private const double CheckBoxHeight = 15.0;
        private const double CheckBoxWidth = 15.0;
        private CheckBox chk = new CheckBox();
        private CompareEventHanlder doCompare;
        private SearchHanlder doQuery;
        public bool IsItemChecked = false;
        public bool IsItemEnable = true;
        private string itemText = string.Empty;
        //internal Grid LayoutRoot;
        private ComparationArea parentControl;
        //internal Canvas rootCanvas;
        private ShowReviewAreaHandler showReview;
        private TextBlock tblContent = new TextBlock();

        public event CompareEventHanlder DoCompare
        {
            [MethodImpl(MethodImplOptions.Synchronized)] add
            {
                this.doCompare = (CompareEventHanlder) Delegate.Combine((Delegate) this.doCompare, (Delegate) value);
            }
            [MethodImpl(MethodImplOptions.Synchronized)] remove
            {
                this.doCompare = (CompareEventHanlder) Delegate.Remove((Delegate) this.doCompare, (Delegate) value);
            }
        }

        public event SearchHanlder DoQuery
        {
            [MethodImpl(MethodImplOptions.Synchronized)] add
            {
                this.doQuery = (SearchHanlder) Delegate.Combine((Delegate) this.doQuery, (Delegate) value);
            }
            [MethodImpl(MethodImplOptions.Synchronized)] remove
            {
                this.doQuery = (SearchHanlder) Delegate.Remove((Delegate) this.doQuery, (Delegate) value);
            }
        }

        public event ShowReviewAreaHandler ShowReview
        {
            [MethodImpl(MethodImplOptions.Synchronized)] add
            {
                this.showReview = (ShowReviewAreaHandler) Delegate.Combine((Delegate) this.showReview, (Delegate) value);
            }
            [MethodImpl(MethodImplOptions.Synchronized)] remove
            {
                this.showReview = (ShowReviewAreaHandler) Delegate.Remove((Delegate) this.showReview, (Delegate) value);
            }
        }

        public ComparationItem()
        {
            this.InitializeComponent();
            base.Loaded += new RoutedEventHandler(this.ComparationItem_Loaded);
        }

        private void chk_Checked(object sender, RoutedEventArgs e)
        {
            for (int i = 0; i < this.parentControl.items.Count; i++)
            {
                ComparationItem item = this.parentControl.items[i];
            }
            this.chk.Tag = base.Tag;
            if (this.doCompare != null)
            {
                this.doCompare(sender, e);
            }
        }

        private void chk_Unchecked(object sender, RoutedEventArgs e)
        {
            if (this.doQuery != null)
            {
                this.doQuery(sender, e);
            }
        }

        public void ClearCheckStatus()
        {
        }

        private void ComparationItem_Loaded(object sender, RoutedEventArgs e)
        {
            this.rootCanvas.Width = base.Width;
            this.rootCanvas.Height = 15.0;
            this.chk.Width = 15.0;
            this.chk.Height = 15.0;
            this.chk.IsChecked = new bool?(this.IsItemChecked);
            this.chk.IsEnabled = this.IsItemEnable;
            this.rootCanvas.Children.Clear();
            this.rootCanvas.Children.Add(this.chk);
            this.tblContent.Text = this.itemText;
            this.tblContent.Width = 80.0;
            this.tblContent.Foreground = new SolidColorBrush(Colors.White);
            this.rootCanvas.Children.Add(this.tblContent);
            this.tblContent.Margin = new Thickness(this.chk.Width + 2.0, 0.0, 0.0, 0.0);
            this.chk.Checked += new RoutedEventHandler(this.chk_Checked);
            this.chk.Unchecked += new RoutedEventHandler(this.chk_Unchecked);
            this.tblContent.MouseEnter += new MouseEventHandler(this.tblContent_MouseEnter);
        }

        //[DebuggerNonUserCode]
        //public void InitializeComponent()
        //{
        //    if (!this._contentLoaded)
        //    {
        //        this._contentLoaded = true;
        //        Application.LoadComponent(this, new Uri("/SinaFinance;component/ChartLibrary/AxisLibrary/ComparationItem.xaml", UriKind.Relative));
        //        this.LayoutRoot = (Grid) base.FindName("LayoutRoot");
        //        this.rootCanvas = (Canvas) base.FindName("rootCanvas");
        //    }
        //}

        private void tblContent_MouseEnter(object sender, MouseEventArgs e)
        {
            if (this.showReview != null)
            {
                this.showReview(sender, e);
            }
        }

        public string ItemText
        {
            get
            {
                return this.itemText;
            }
            set
            {
                this.itemText = value;
            }
        }

        public ComparationArea ParentControl
        {
            get
            {
                return this.parentControl;
            }
            set
            {
                this.parentControl = value;
            }
        }

        public delegate void CompareEventHanlder(object sender, RoutedEventArgs e);

        public delegate void SearchHanlder(object sender, RoutedEventArgs e);

        public delegate void ShowReviewAreaHandler(object sender, MouseEventArgs e);
    }
}
